package 链表;
/*
 * https://leetcode-cn.com/problems/linked-list-cycle/
 * */



public class _141_环形链表 {
	public boolean hasCycle(ListNode head) {
		if (head != null && head.next != null && head.next.next != null) {
			ListNode slowListNode = head;

			ListNode fastListNode = head.next.next;
			while (fastListNode != null) {
				if (slowListNode.val == fastListNode.val) {
					return true;
				}
				slowListNode = slowListNode.next;
				if (fastListNode.next != null && fastListNode.next.next != null ) {
					fastListNode = fastListNode.next.next;
				} else {
					return false;
				}
			}
		}

		return false;
//		
//		Boolean boolean1 = false;
//		while (head != null) {
//			ListNode newHead = head.next;
//			while (newHead != null) {
//				if (head.val != newHead.val) {
//					newHead = newHead.next;
//				} else {
//					boolean1 = true;
//					break;
//				}
//			}
//			head = head.next;
//		}
//		return boolean1;
	}
}
